package com.tchepannou.limbe.validation;

import com.tchepannou.util.StringUtil;

import java.lang.reflect.Field;

/**
 * User: herve
 * Date: 14-01-12 12:31 PM
 */
public class ValidEmailValidator extends AbstractValidator
{
    @Override
    public boolean validate(Object bean, Field field)
    {
        Object value = getValue(bean, field);
        if (value == null)
        {
            return true;
        }
        else if (value instanceof String)
        {
            return ((String) value).length()==0 || StringUtil.isEmail((String)value);
        }
        else
        {
            return false;
        }
    }

    @Override
    public boolean validate(Object bean)
    {
        return false;
    }
}
